using System;
using System.ComponentModel.Design;
using System.Globalization;
using PickGold.Charting.Borders3D;
using PickGold.Charting.ChartTypes;
using PickGold.Charting.Data;
using PickGold.Charting.Formulas;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	internal class CommonElements
	{
		private Chart _chart;
		private ChartImage _chartPicture;
		private int _height;
		private int _width;
		internal IServiceContainer container;
		internal ChartGraphics graph;
		internal bool processModePaint = true;
		internal bool processModeRegions;

		internal CommonElements(IServiceContainer container)
		{
			this.container = container;
		}

		internal static double ParseDouble(string stringToParse)
		{
			return ParseDouble(stringToParse, false);
		}

		internal static double ParseDouble(string stringToParse, bool throwException)
		{
			double result = 0.0;
			if (throwException)
			{
				return double.Parse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture);
			}
			if (!double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
			{
				double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result);
			}
			return result;
		}

		internal static float ParseFloat(string stringToParse)
		{
			float result = 0f;
			if (!float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
			{
				float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result);
			}
			return result;
		}

		internal BorderTypeRegistry BorderTypeRegistry
		{
			get
			{
				return (BorderTypeRegistry)this.container.GetService(typeof(BorderTypeRegistry));
			}
		}

		internal Chart Chart
		{
			get
			{
				if (this._chart == null)
				{
					this._chart = (Chart)this.container.GetService(typeof(Chart));
				}
				return this._chart;
			}
		}

		internal ChartImage ChartPicture
		{
			get
			{
				if (this._chartPicture == null)
				{
					this._chartPicture = (ChartImage)this.container.GetService(typeof(ChartImage));
				}
				return this._chartPicture;
			}
		}

		internal ChartTypeRegistry ChartTypeRegistry
		{
			get
			{
				return (ChartTypeRegistry)this.container.GetService(typeof(ChartTypeRegistry));
			}
		}

		internal DataManager DataManager
		{
			get
			{
				return (DataManager)this.container.GetService(typeof(DataManager));
			}
		}

		public DataManipulator DataManipulator
		{
			get
			{
				return this.ChartPicture.DataManipulator;
			}
		}

		internal FormulaRegistry FormulaRegistry
		{
			get
			{
				return (FormulaRegistry)this.container.GetService(typeof(FormulaRegistry));
			}
		}

		internal int Height
		{
			get
			{
				return this._height;
			}
			set
			{
				this._height = value;
			}
		}

		public HotRegionsList HotRegionsList
		{
			get
			{
				return this.ChartPicture.hotRegionsList;
			}
		}

		internal ImageLoader ImageLoader
		{
			get
			{
				return (ImageLoader)this.container.GetService(typeof(ImageLoader));
			}
		}

		public bool ProcessModePaint
		{
			get
			{
				return this.processModePaint;
			}
		}

		public bool ProcessModeRegions
		{
			get
			{
				return this.processModeRegions;
			}
		}

		internal int Width
		{
			get
			{
				return this._width;
			}
			set
			{
				this._width = value;
			}
		}
	}
}

